<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="spring" 	uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="tiles" 	uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c"		uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" pageEncoding="utf-8"%>
 <script>
$(document).ready(function () {
    setMenuSelection("adauga");
     $("#btList").kendoButton({icon: "funnel"});
     $("#btCard").kendoButton({icon: "plus"});
     $("#btApplyFilter").kendoButton({icon: "tick"});
    	
	 var crudServiceBaseUrl = "json/listRefBranchREST",
        dataSource = new kendo.data.DataSource({
                transport: {
                    read:  {
                        url: crudServiceBaseUrl + "/List",
                        dataType: "json"
                    },
                    update: {
                        url: crudServiceBaseUrl + "/Update",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8"
                    },
                    destroy: {
                        url: crudServiceBaseUrl + "/Destroy",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8"
                    },
                    create: {
                        url: crudServiceBaseUrl + "/Create",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8"
                    },
                   parameterMap: function(options, operation) {
                       if (operation !== "read" && options) {
                           	if (options.status.toString().localeCompare("true") == 0 ) {
                           		options.status = 1;
                           	} else {
                           		options.status = 0;
                           	}
                          	return kendo.stringify(options);
                       }
                   }
                },
                requestEnd: function(e) {
                    var type = e.type;
                    if (type != "read") { this.read(); }
                },
                batch: false,
                pageSize: 20,
                schema: {
                    model: {
                        id: "id",
                        fields: {
                            id: 	  { editable: false, nullable: true },
                            nlsValue: { validation: { required: false } },
                            mdValue:  { validation: { required: true } },
                            ruValue:  { validation: { required: true } },
                            enValue:  { validation: { required: true } },
                            endDate:  { validation: { required: false } },
                            status:   { type: "boolean" },
                            updatedBy: { validation: { required: false } },
                            updatedDate:  { validation: { required: false } }
                         }
                    }
                }
            });
	 
	 

     $("#gridList").kendoGrid({
         dataSource: dataSource,
         selectable: "single",
         pageable: true,
         height: 430,
         toolbar: ["create"],
         columns: [
             { field:"mdValue", title: "Denumirea"},
             { field: "status", title: "Activ",  width: "100px" , template: renderStatus },
             { command: ["edit", "destroy"], title: "&nbsp;", width: "160px" }],
         editable: "popup"
     });
     
     
});



function  renderStatus (dataItem, b, c) {
	if (dataItem.status == "0" ||  dataItem.status == "false") {	
		return "<div style='background:red'> "+ dataItem.status +" </div>";
	}
	return  dataItem.status;
};    
    
    
function btApplyClick(){
	$("#gridList").data("kendoGrid").dataSource.read();
	$("#gridList").data("kendoGrid").refresh();
};    
</script>

<CENTER>
<p style="text-align: left;">
	<span> Filiale </span>
<!-- 	<button id="btList" type="button" 	onclick="javascript:window.open('vizualizeazaDomenii', 	target='_self')";>Lista filiale</button> -->
<!-- 	<button id="btCard" type="button"  	onclick="javascript:window.open('adaugaDomeniu', 		target='_self')";>Adaugă filial</button> -->
<!-- 	<button id="btApplyFilter" type="button"	onclick="btApplyClick()" >Aplica</button> -->
	<c:if test="${errorMessage != '' &&  errorMessage != '0'}">
		<span id="errorMessage" class="errorMessage"> ${errorMessage} </span>
	</c:if>
</p>
<div id="gridList"></div>
</center>

  